from django.db import models

#Create your models here.
class Users(models.Model):
    uID = models.CharField(primary_key=True,max_length=64)  #用户ID
    openID=models.CharField(max_length=64) #openID
    pwd=models.CharField(max_length=64) #密码
    uName = models.CharField(max_length=16,null=True)
    gender = models.BinaryField(null=True)#TODO:性别

#
# class Contacts(models.Model):
#     #TODO:联系人ID要用微信的ID，不知道要不要用django自己的ID
#     openID = models.CharField(max_length=50)
#     remark=models.CharField(max_length=16,null=True)
#     Tag = models.CharField(max_length=16,null=True)

# class Groups(models.Model):
#     Gname = models.CharField(max_length=8,null=False)
#     Create_at = models.DateField()
#
# class GroupContacts(models.Model):
#     Cid = models.ForeignKey(Contacts,on_delete=models.CASCADE)
#     Uid = models.ForeignKey(Users,on_delete=models.CASCADE)



class Events(models.Model):
    #TODO RUid = 接受ID不知道怎么写,待讨论，是接受人？还是接受什么？
    Ename = models.CharField(max_length=32,null=False)
    uID= models.ForeignKey('Users',on_delete=models.CASCADE)
    Estartat = models.DateField()   #事件开始日期
    EstartTime=models.TimeField()   #事件开始时间
    Eendat = models.DateField()     #事件结束日期
    EendTime=models.TimeField()     #事件结束时间
    EfinishDate=models.DateField(null=True)  #事件完成日期
    EexpectDate = models.DateField(null=True)  #事件预期日期
    EexpectTime=models.TimeField(null=True)  #事件预期时间
    Enature=models.CharField(max_length=16,null=True) #事件性质
    EisSubTodo=models.BooleanField()    #是否为子任务
    Erepeat=models.BooleanField()  #是否重复
    Elevel = models.IntegerField(default=0,null=True)  #事件等级
    Estatus = models.BooleanField()  #事件完成状态
    Ecomment = models.IntegerField(default=0,null=True) #事件完成等级评价
    Edesc=models.CharField(max_length=200,null=True)    #事件描述



class EventsLaunch(models.Model):
    #TODO ELid 用django生成的还是自己来？
    # Cid = models.ForeignKey(Contacts,on_delete=models.CASCADE)
    uID = models.ForeignKey('Users',on_delete=models.CASCADE)
    #SendRole = models.CharField(max_length=16,null=False)
    #SendName = models.CharField(max_length=8,null=False)
    #SendRemark = models.CharField(max_length=32,null=False)
    eName=models.CharField(max_length=32,null=False)
    began=models.DateField()
    Send_at = models.DateField()
    #RULevel = models.IntegerField(default=0) #TODO 是否可为空
    #RUSpeed = models.IntegerField(default=0)

class EventsReceive(models.Model):
    # Cid = models.ForeignKey(Contacts,on_delete=models.CASCADE)
    ELid = models.ForeignKey(EventsLaunch,on_delete=models.CASCADE) #联系发起事件ID
    Eventid = models.ForeignKey(Events, on_delete=models.CASCADE)   #联系事件ID
    Receive_at = models.DateField() #接收时间


# class UserAbility(models.Model):
#     Eid = models.ForeignKey(Events,on_delete=models.CASCADE)
#     uID = models.ForeignKey('Users', on_delete=models.CASCADE)
#     Ability = models.IntegerField(default=0,null=False)
#     AbilityLevel = models.IntegerField(default=0,null=False)
#     Speed = models.IntegerField(default=0,null=False)
#     #TODO 等级评定时间不知道是什么不知道怎么写


# class MassageRecords(models.Model):
#     Cid = models.ForeignKey(Contacts,on_delete=models.CASCADE)
#     Uid = models.ForeignKey(Users,on_delete=models.CASCADE)
#     Content = models.CharField(max_length=128)
#     SendTime = models.DateField()#TODO: 不知道默认值要怎么写




class EventsContact(models.Model):
    Ecid = models.ForeignKey(Events,on_delete=models.CASCADE,related_name='eventID')    #大事件
    EDcid = models.ForeignKey(Events,on_delete=models.CASCADE,related_name='eventLinkID')#被关联的小事件